package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsOrderGoodsMapper;
import com.qf.pojo.DtsOrderGoods;
import com.qf.service.DtsGoodsService;
import com.qf.service.DtsOrderGoodsService;
import com.qf.util.ResponseUtil;
import com.qf.vo.GoodsOrderVo;
import com.qf.vo.StatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/24 13:09
 */
@Service
public class DtsOrderGoodsServiceImpl implements DtsOrderGoodsService {
    @Autowired
    private DtsOrderGoodsMapper dtsOrderGoodsMapper;
    @Override
    public List<DtsOrderGoods> selectByOrderId(Integer id) {
        return dtsOrderGoodsMapper.selectList(new QueryWrapper<DtsOrderGoods>().eq("order_id",id));
    }

    @Override
    public StatVo findGoodsStatRows() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<GoodsOrderVo> goodsOrderStatVoList = dtsOrderGoodsMapper.selectGoodsStatRows();
        List<Map> rows = new ArrayList<>();
        for (int i = goodsOrderStatVoList.size()-1; i >= 0; i--) {
            GoodsOrderVo goodsOrderStatVo = goodsOrderStatVoList.get(i);
            Map map = new HashMap();
            map.put("amount",goodsOrderStatVo.getAmount());
            map.put("orders", goodsOrderStatVo.getOrders());
            map.put("day", df.format(goodsOrderStatVo.getDay()));
            map.put("products", goodsOrderStatVo.getProducts());
            rows.add(map);
        }
        String[] columns = new String[]{"day","orders","products","amount"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return statVo;
    }
}
